package com.zhiqiang.gameserver.nettydemo.discard;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class DiscardServerHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        /**
         * 释放bytebuf类型的数据
         */
//        ((ByteBuf) msg).release();
//        ByteBuf in = (ByteBuf) msg;
//        try {
//            System.out.println(in.toString(io.nettydemo.util.CharsetUtil.US_ASCII));
//        } finally {
//           in.release();
//        }
        //echo
        ctx.writeAndFlush(msg);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        // 当出现异常就关闭连接
        cause.printStackTrace();//打印异常
        ctx.close();//关闭连接
    }
}
